home *** CD-ROM | disk | FTP | other *** search
/ Kellogg's Amérique / Kellogg's Amérique / amazonie_en_danger.swf / scripts / fl / core / UIComponent.as < prev   
Text File  |  2020-08-04  |  20KB  |  730 lines

  1. package fl.core
  2. {
  3.    import fl.events.ComponentEvent;
  4.    import fl.managers.FocusManager;
  5.    import fl.managers.IFocusManager;
  6.    import fl.managers.IFocusManagerComponent;
  7.    import fl.managers.StyleManager;
  8.    import flash.display.DisplayObject;
  9.    import flash.display.InteractiveObject;
  10.    import flash.display.Sprite;
  11.    import flash.events.Event;
  12.    import flash.events.FocusEvent;
  13.    import flash.events.KeyboardEvent;
  14.    import flash.system.IME;
  15.    import flash.system.IMEConversionMode;
  16.    import flash.text.TextField;
  17.    import flash.text.TextFormat;
  18.    import flash.text.TextFormatAlign;
  19.    import flash.utils.Dictionary;
  20.    import flash.utils.getDefinitionByName;
  21.    import flash.utils.getQualifiedClassName;
  22.    
  23.    public class UIComponent extends Sprite
  24.    {
  25.       
  26.       public static var inCallLaterPhase:Boolean = false;
  27.       
  28.       private static var defaultStyles:Object = {
  29.          "focusRectSkin":"focusRectSkin",
  30.          "focusRectPadding":2,
  31.          "textFormat":new TextFormat("_sans",11,0,false,false,false,"","",TextFormatAlign.LEFT,0,0,0,0),
  32.          "disabledTextFormat":new TextFormat("_sans",11,10066329,false,false,false,"","",TextFormatAlign.LEFT,0,0,0,0),
  33.          "defaultTextFormat":new TextFormat("_sans",11,0,false,false,false,"","",TextFormatAlign.LEFT,0,0,0,0),
  34.          "defaultDisabledTextFormat":new TextFormat("_sans",11,10066329,false,false,false,"","",TextFormatAlign.LEFT,0,0,0,0)
  35.       };
  36.       
  37.       public static var createAccessibilityImplementation:Function;
  38.       
  39.       private static var focusManagers:Dictionary = new Dictionary(false);
  40.        
  41.       
  42.       protected var _enabled:Boolean = true;
  43.       
  44.       private var _mouseFocusEnabled:Boolean = true;
  45.       
  46.       protected var startHeight:Number;
  47.       
  48.       protected var _height:Number;
  49.       
  50.       protected var _oldIMEMode:String = null;
  51.       
  52.       protected var startWidth:Number;
  53.       
  54.       public var focusTarget:IFocusManagerComponent;
  55.       
  56.       protected var errorCaught:Boolean = false;
  57.       
  58.       protected var uiFocusRect:DisplayObject;
  59.       
  60.       protected var _width:Number;
  61.       
  62.       public var version:String = "3.0.0.15";
  63.       
  64.       protected var isFocused:Boolean = false;
  65.       
  66.       protected var callLaterMethods:Dictionary;
  67.       
  68.       private var _focusEnabled:Boolean = true;
  69.       
  70.       private var tempText:TextField;
  71.       
  72.       protected var invalidateFlag:Boolean = false;
  73.       
  74.       protected var _inspector:Boolean = false;
  75.       
  76.       protected var sharedStyles:Object;
  77.       
  78.       protected var invalidHash:Object;
  79.       
  80.       protected var isLivePreview:Boolean = false;
  81.       
  82.       protected var _imeMode:String = null;
  83.       
  84.       protected var instanceStyles:Object;
  85.       
  86.       protected var _x:Number;
  87.       
  88.       protected var _y:Number;
  89.       
  90.       public function UIComponent()
  91.       {
  92.          version = "3.0.0.15";
  93.          isLivePreview = false;
  94.          invalidateFlag = false;
  95.          _enabled = true;
  96.          isFocused = false;
  97.          _focusEnabled = true;
  98.          _mouseFocusEnabled = true;
  99.          _imeMode = null;
  100.          _oldIMEMode = null;
  101.          errorCaught = false;
  102.          _inspector = false;
  103.          super();
  104.          instanceStyles = {};
  105.          sharedStyles = {};
  106.          invalidHash = {};
  107.          callLaterMethods = new Dictionary();
  108.          StyleManager.registerInstance(this);
  109.          configUI();
  110.          invalidate(InvalidationType.ALL);
  111.          tabEnabled = this is IFocusManagerComponent;
  112.          focusRect = false;
  113.          if(tabEnabled)
  114.          {
  115.             addEventListener(FocusEvent.FOCUS_IN,focusInHandler);
  116.             addEventListener(FocusEvent.FOCUS_OUT,focusOutHandler);
  117.             addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);
  118.             addEventListener(KeyboardEvent.KEY_UP,keyUpHandler);
  119.          }
  120.          initializeFocusManager();
  121.          addEventListener(Event.ENTER_FRAME,hookAccessibility,false,0,true);
  122.       }
  123.       
  124.       public static function getStyleDefinition() : Object
  125.       {
  126.          return defaultStyles;
  127.       }
  128.       
  129.       public static function mergeStyles(... rest) : Object
  130.       {
  131.          var _loc2_:Object = null;
  132.          var _loc3_:uint = 0;
  133.          var _loc4_:uint = 0;
  134.          var _loc5_:Object = null;
  135.          var _loc6_:* = null;
  136.          _loc2_ = {};
  137.          _loc3_ = rest.length;
  138.          _loc4_ = 0;
  139.          while(_loc4_ < _loc3_)
  140.          {
  141.             _loc5_ = rest[_loc4_];
  142.             for(_loc6_ in _loc5_)
  143.             {
  144.                if(_loc2_[_loc6_] == null)
  145.                {
  146.                   _loc2_[_loc6_] = rest[_loc4_][_loc6_];
  147.                }
  148.             }
  149.             _loc4_++;
  150.          }
  151.          return _loc2_;
  152.       }
  153.       
  154.       public function drawFocus(param1:Boolean) : void
  155.       {
  156.          var _loc2_:Number = NaN;
  157.          isFocused = param1;
  158.          if(uiFocusRect != null && contains(uiFocusRect))
  159.          {
  160.             removeChild(uiFocusRect);
  161.             uiFocusRect = null;
  162.          }
  163.          if(param1)
  164.          {
  165.             uiFocusRect = getDisplayObjectInstance(getStyleValue("focusRectSkin")) as Sprite;
  166.             if(uiFocusRect == null)
  167.             {
  168.                return;
  169.             }
  170.             _loc2_ = Number(getStyleValue("focusRectPadding"));
  171.             uiFocusRect.x = -_loc2_;
  172.             uiFocusRect.y = -_loc2_;
  173.             uiFocusRect.width = width + _loc2_ * 2;
  174.             uiFocusRect.height = height + _loc2_ * 2;
  175.             addChildAt(uiFocusRect,0);
  176.          }
  177.       }
  178.       
  179.       private function callLaterDispatcher(param1:Event) : void
  180.       {
  181.          var _loc2_:Dictionary = null;
  182.          var _loc3_:* = null;
  183.          if(param1.type == Event.ADDED_TO_STAGE)
  184.          {
  185.             removeEventListener(Event.ADDED_TO_STAGE,callLaterDispatcher);
  186.             stage.addEventListener(Event.RENDER,callLaterDispatcher,false,0,true);
  187.             stage.invalidate();
  188.             return;
  189.          }
  190.          param1.target.removeEventListener(Event.RENDER,callLaterDispatcher);
  191.          if(stage == null)
  192.          {
  193.             addEventListener(Event.ADDED_TO_STAGE,callLaterDispatcher,false,0,true);
  194.             return;
  195.          }
  196.          inCallLaterPhase = true;
  197.          _loc2_ = callLaterMethods;
  198.          for(_loc3_ in _loc2_)
  199.          {
  200.             _loc3_();
  201.             delete _loc2_[_loc3_];
  202.          }
  203.          inCallLaterPhase = false;
  204.       }
  205.       
  206.       private function addedHandler(param1:Event) : void
  207.       {
  208.          removeEventListener("addedToStage",addedHandler);
  209.          initializeFocusManager();
  210.       }
  211.       
  212.       protected function getStyleValue(param1:String) : Object
  213.       {
  214.          return instanceStyles[param1] == null ? sharedStyles[param1] : instanceStyles[param1];
  215.       }
  216.       
  217.       protected function isOurFocus(param1:DisplayObject) : Boolean
  218.       {
  219.          return param1 == this;
  220.       }
  221.       
  222.       override public function get scaleX() : Number
  223.       {
  224.          return width / startWidth;
  225.       }
  226.       
  227.       override public function get scaleY() : Number
  228.       {
  229.          return height / startHeight;
  230.       }
  231.       
  232.       override public function set height(param1:Number) : void
  233.       {
  234.          if(_height == param1)
  235.          {
  236.             return;
  237.          }
  238.          setSize(width,param1);
  239.       }
  240.       
  241.       protected function keyDownHandler(param1:KeyboardEvent) : void
  242.       {
  243.       }
  244.       
  245.       protected function focusInHandler(param1:FocusEvent) : void
  246.       {
  247.          var _loc2_:IFocusManager = null;
  248.          if(isOurFocus(param1.target as DisplayObject))
  249.          {
  250.             _loc2_ = focusManager;
  251.             if(_loc2_ && _loc2_.showFocusIndicator)
  252.             {
  253.                drawFocus(true);
  254.                isFocused = true;
  255.             }
  256.          }
  257.       }
  258.       
  259.       public function setStyle(param1:String, param2:Object) : void
  260.       {
  261.          if(instanceStyles[param1] === param2 && !(param2 is TextFormat))
  262.          {
  263.             return;
  264.          }
  265.          instanceStyles[param1] = param2;
  266.          invalidate(InvalidationType.STYLES);
  267.       }
  268.       
  269.       override public function get visible() : Boolean
  270.       {
  271.          return super.visible;
  272.       }
  273.       
  274.       public function get componentInspectorSetting() : Boolean
  275.       {
  276.          return _inspector;
  277.       }
  278.       
  279.       override public function get x() : Number
  280.       {
  281.          return !!isNaN(_x) ? Number(super.x) : Number(_x);
  282.       }
  283.       
  284.       override public function get y() : Number
  285.       {
  286.          return !!isNaN(_y) ? Number(super.y) : Number(_y);
  287.       }
  288.       
  289.       protected function setIMEMode(param1:Boolean) : *
  290.       {
  291.          var enabled:Boolean = param1;
  292.          if(_imeMode != null)
  293.          {
  294.             if(enabled)
  295.             {
  296.                IME.enabled = true;
  297.                _oldIMEMode = IME.conversionMode;
  298.                try
  299.                {
  300.                   if(!errorCaught && IME.conversionMode != IMEConversionMode.UNKNOWN)
  301.                   {
  302.                      IME.conversionMode = _imeMode;
  303.                   }
  304.                   errorCaught = false;
  305.                }
  306.                catch(e:Error)
  307.                {
  308.                   errorCaught = true;
  309.                   throw new Error("IME mode not supported: " + _imeMode);
  310.                }
  311.             }
  312.             else
  313.             {
  314.                if(IME.conversionMode != IMEConversionMode.UNKNOWN && _oldIMEMode != IMEConversionMode.UNKNOWN)
  315.                {
  316.                   IME.conversionMode = _oldIMEMode;
  317.                }
  318.                IME.enabled = false;
  319.             }
  320.          }
  321.       }
  322.       
  323.       public function set enabled(param1:Boolean) : void
  324.       {
  325.          if(param1 == _enabled)
  326.          {
  327.             return;
  328.          }
  329.          _enabled = param1;
  330.          invalidate(InvalidationType.STATE);
  331.       }
  332.       
  333.       public function setSharedStyle(param1:String, param2:Object) : void
  334.       {
  335.          if(sharedStyles[param1] === param2 && !(param2 is TextFormat))
  336.          {
  337.             return;
  338.          }
  339.          sharedStyles[param1] = param2;
  340.          if(instanceStyles[param1] == null)
  341.          {
  342.             invalidate(InvalidationType.STYLES);
  343.          }
  344.       }
  345.       
  346.       protected function keyUpHandler(param1:KeyboardEvent) : void
  347.       {
  348.       }
  349.       
  350.       public function set focusEnabled(param1:Boolean) : void
  351.       {
  352.          _focusEnabled = param1;
  353.       }
  354.       
  355.       override public function set scaleX(param1:Number) : void
  356.       {
  357.          setSize(startWidth * param1,height);
  358.       }
  359.       
  360.       public function get mouseFocusEnabled() : Boolean
  361.       {
  362.          return _mouseFocusEnabled;
  363.       }
  364.       
  365.       override public function set scaleY(param1:Number) : void
  366.       {
  367.          setSize(width,startHeight * param1);
  368.       }
  369.       
  370.       protected function getDisplayObjectInstance(param1:Object) : DisplayObject
  371.       {
  372.          var classDef:Object = null;
  373.          var skin:Object = param1;
  374.          classDef = null;
  375.          if(skin is Class)
  376.          {
  377.             return new skin() as DisplayObject;
  378.          }
  379.          if(skin is DisplayObject)
  380.          {
  381.             (skin as DisplayObject).x = 0;
  382.             (skin as DisplayObject).y = 0;
  383.             return skin as DisplayObject;
  384.          }
  385.          try
  386.          {
  387.             classDef = getDefinitionByName(skin.toString());
  388.          }
  389.          catch(e:Error)
  390.          {
  391.             try
  392.             {
  393.                classDef = loaderInfo.applicationDomain.getDefinition(skin.toString()) as Object;
  394.             }
  395.             catch(e:Error)
  396.             {
  397.             }
  398.          }
  399.          if(classDef == null)
  400.          {
  401.             return null;
  402.          }
  403.          return new classDef() as DisplayObject;
  404.       }
  405.       
  406.       protected function copyStylesToChild(param1:UIComponent, param2:Object) : void
  407.       {
  408.          var _loc3_:* = null;
  409.          for(_loc3_ in param2)
  410.          {
  411.             param1.setStyle(_loc3_,getStyleValue(param2[_loc3_]));
  412.          }
  413.       }
  414.       
  415.       protected function beforeComponentParameters() : void
  416.       {
  417.       }
  418.       
  419.       protected function callLater(param1:Function) : void
  420.       {
  421.          if(inCallLaterPhase)
  422.          {
  423.             return;
  424.          }
  425.          callLaterMethods[param1] = true;
  426.          if(stage != null)
  427.          {
  428.             stage.addEventListener(Event.RENDER,callLaterDispatcher,false,0,true);
  429.             stage.invalidate();
  430.          }
  431.          else
  432.          {
  433.             addEventListener(Event.ADDED_TO_STAGE,callLaterDispatcher,false,0,true);
  434.          }
  435.       }
  436.       
  437.       protected function createFocusManager() : void
  438.       {
  439.          if(focusManagers[stage] == null)
  440.          {
  441.             focusManagers[stage] = new FocusManager(stage);
  442.          }
  443.       }
  444.       
  445.       override public function set visible(param1:Boolean) : void
  446.       {
  447.          var _loc2_:String = null;
  448.          if(super.visible == param1)
  449.          {
  450.             return;
  451.          }
  452.          super.visible = param1;
  453.          _loc2_ = !!param1 ? ComponentEvent.SHOW : ComponentEvent.HIDE;
  454.          dispatchEvent(new ComponentEvent(_loc2_,true));
  455.       }
  456.       
  457.       protected function hookAccessibility(param1:Event) : void
  458.       {
  459.          removeEventListener(Event.ENTER_FRAME,hookAccessibility);
  460.          initializeAccessibility();
  461.       }
  462.       
  463.       public function set componentInspectorSetting(param1:Boolean) : void
  464.       {
  465.          _inspector = param1;
  466.          if(_inspector)
  467.          {
  468.             beforeComponentParameters();
  469.          }
  470.          else
  471.          {
  472.             afterComponentParameters();
  473.          }
  474.       }
  475.       
  476.       override public function set x(param1:Number) : void
  477.       {
  478.          move(param1,_y);
  479.       }
  480.       
  481.       public function drawNow() : void
  482.       {
  483.          draw();
  484.       }
  485.       
  486.       override public function set y(param1:Number) : void
  487.       {
  488.          move(_x,param1);
  489.       }
  490.       
  491.       protected function checkLivePreview() : Boolean
  492.       {
  493.          var className:String = null;
  494.          if(parent == null)
  495.          {
  496.             return false;
  497.          }
  498.          try
  499.          {
  500.             className = getQualifiedClassName(parent);
  501.          }
  502.          catch(e:Error)
  503.          {
  504.          }
  505.          return className == "fl.livepreview::LivePreviewParent";
  506.       }
  507.       
  508.       protected function focusOutHandler(param1:FocusEvent) : void
  509.       {
  510.          if(isOurFocus(param1.target as DisplayObject))
  511.          {
  512.             drawFocus(false);
  513.             isFocused = false;
  514.          }
  515.       }
  516.       
  517.       public function set mouseFocusEnabled(param1:Boolean) : void
  518.       {
  519.          _mouseFocusEnabled = param1;
  520.       }
  521.       
  522.       public function getFocus() : InteractiveObject
  523.       {
  524.          if(stage)
  525.          {
  526.             return stage.focus;
  527.          }
  528.          return null;
  529.       }
  530.       
  531.       protected function validate() : void
  532.       {
  533.          invalidHash = {};
  534.       }
  535.       
  536.       override public function get height() : Number
  537.       {
  538.          return _height;
  539.       }
  540.       
  541.       public function invalidate(param1:String = "all", param2:Boolean = true) : void
  542.       {
  543.          invalidHash[param1] = true;
  544.          if(param2)
  545.          {
  546.             this.callLater(draw);
  547.          }
  548.       }
  549.       
  550.       public function get enabled() : Boolean
  551.       {
  552.          return _enabled;
  553.       }
  554.       
  555.       protected function getScaleX() : Number
  556.       {
  557.          return super.scaleX;
  558.       }
  559.       
  560.       protected function getScaleY() : Number
  561.       {
  562.          return super.scaleY;
  563.       }
  564.       
  565.       public function get focusEnabled() : Boolean
  566.       {
  567.          return _focusEnabled;
  568.       }
  569.       
  570.       protected function afterComponentParameters() : void
  571.       {
  572.       }
  573.       
  574.       protected function draw() : void
  575.       {
  576.          if(isInvalid(InvalidationType.SIZE,InvalidationType.STYLES))
  577.          {
  578.             if(isFocused && focusManager.showFocusIndicator)
  579.             {
  580.                drawFocus(true);
  581.             }
  582.          }
  583.          validate();
  584.       }
  585.       
  586.       protected function configUI() : void
  587.       {
  588.          var _loc1_:Number = NaN;
  589.          var _loc2_:Number = NaN;
  590.          var _loc3_:Number = NaN;
  591.          isLivePreview = checkLivePreview();
  592.          _loc1_ = rotation;
  593.          rotation = 0;
  594.          _loc2_ = super.width;
  595.          _loc3_ = super.height;
  596.          super.scaleX = super.scaleY = 1;
  597.          setSize(_loc2_,_loc3_);
  598.          move(super.x,super.y);
  599.          rotation = _loc1_;
  600.          startWidth = _loc2_;
  601.          startHeight = _loc3_;
  602.          if(numChildren > 0)
  603.          {
  604.             removeChildAt(0);
  605.          }
  606.       }
  607.       
  608.       protected function setScaleX(param1:Number) : void
  609.       {
  610.          super.scaleX = param1;
  611.       }
  612.       
  613.       protected function setScaleY(param1:Number) : void
  614.       {
  615.          super.scaleY = param1;
  616.       }
  617.       
  618.       private function initializeFocusManager() : void
  619.       {
  620.          if(stage == null)
  621.          {
  622.             addEventListener(Event.ADDED_TO_STAGE,addedHandler,false,0,true);
  623.          }
  624.          else
  625.          {
  626.             createFocusManager();
  627.          }
  628.       }
  629.       
  630.       public function set focusManager(param1:IFocusManager) : void
  631.       {
  632.          UIComponent.focusManagers[this] = param1;
  633.       }
  634.       
  635.       public function clearStyle(param1:String) : void
  636.       {
  637.          setStyle(param1,null);
  638.       }
  639.       
  640.       protected function isInvalid(param1:String, ... rest) : Boolean
  641.       {
  642.          if(invalidHash[param1] || invalidHash[InvalidationType.ALL])
  643.          {
  644.             return true;
  645.          }
  646.          while(rest.length > 0)
  647.          {
  648.             if(invalidHash[rest.pop()])
  649.             {
  650.                return true;
  651.             }
  652.          }
  653.          return false;
  654.       }
  655.       
  656.       public function setSize(param1:Number, param2:Number) : void
  657.       {
  658.          _width = param1;
  659.          _height = param2;
  660.          invalidate(InvalidationType.SIZE);
  661.          dispatchEvent(new ComponentEvent(ComponentEvent.RESIZE,false));
  662.       }
  663.       
  664.       override public function set width(param1:Number) : void
  665.       {
  666.          if(_width == param1)
  667.          {
  668.             return;
  669.          }
  670.          setSize(param1,height);
  671.       }
  672.       
  673.       public function setFocus() : void
  674.       {
  675.          if(stage)
  676.          {
  677.             stage.focus = this;
  678.          }
  679.       }
  680.       
  681.       protected function initializeAccessibility() : void
  682.       {
  683.          if(UIComponent.createAccessibilityImplementation != null)
  684.          {
  685.             UIComponent.createAccessibilityImplementation(this);
  686.          }
  687.       }
  688.       
  689.       public function get focusManager() : IFocusManager
  690.       {
  691.          var _loc1_:DisplayObject = null;
  692.          _loc1_ = this;
  693.          while(_loc1_)
  694.          {
  695.             if(UIComponent.focusManagers[_loc1_] != null)
  696.             {
  697.                return IFocusManager(UIComponent.focusManagers[_loc1_]);
  698.             }
  699.             _loc1_ = _loc1_.parent;
  700.          }
  701.          return null;
  702.       }
  703.       
  704.       override public function get width() : Number
  705.       {
  706.          return _width;
  707.       }
  708.       
  709.       public function move(param1:Number, param2:Number) : void
  710.       {
  711.          _x = param1;
  712.          _y = param2;
  713.          super.x = Math.round(param1);
  714.          super.y = Math.round(param2);
  715.          dispatchEvent(new ComponentEvent(ComponentEvent.MOVE));
  716.       }
  717.       
  718.       public function validateNow() : void
  719.       {
  720.          invalidate(InvalidationType.ALL,false);
  721.          draw();
  722.       }
  723.       
  724.       public function getStyle(param1:String) : Object
  725.       {
  726.          return instanceStyles[param1];
  727.       }
  728.    }
  729. }
  730.